﻿
(function () {
    "use strict";

    F.Delegate = function (func, context, args) {
        var self = this;
        self.fns = []

        if (func)
            self.add(func, context, args);
    };

    var dp = F.Delegate.prototype;

    dp.fire = function (args) {
        var self = this;
        for (var i = 0, length = self.fns.length; i < length; i++) {
            var element = self.fns[i];
            if (element.callback) {
                if (element.context) {
                    element.callback.apply(element.context, arguments);
                } else {
                    element.callback.apply(this, arguments)
                }
            }
        }
    }

    dp.add = function (func, context, args) {
        if (!func)
            return;
        var self = this;
        self.fns.push({ callback: func, context: context, args: args });
    };

    dp = null;
} ());